import { resources, SpriteFrame } from "cc"

export class ResourcesManager{
  private static instance: ResourcesManager

  static getInstance(): ResourcesManager {
    return this.instance || (this.instance = new ResourcesManager())
  }

  loadRes(path: string, type: typeof SpriteFrame = SpriteFrame): Promise<SpriteFrame[]> {
    return new Promise( (resolve, reject) => {

      resources.loadDir(path, type, (err, assets) => {
        if (err) {
          reject(err)
          return
        }
        resolve(assets)
      })

    })

  }

}

